import 'package:flutter/material.dart';

import 'package:flutter_swiper/flutter_swiper.dart';
import 'package:sexy_tea/model/home_grid_model.dart';
import 'package:sexy_tea/widgets/load_image.dart';

import 'http/api.dart';
import 'http/http_manager.dart';
import 'http/result_data.dart';

void main() => runApp(new MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      title: 'Flutter Demo',
      theme: new ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: new MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => new _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

  void _testRequest() async {
    ResultData res = await Api.getHomeGrid();
    if (res.isSuccess) {
      HomeGridModel homeGridModel = HomeGridModel().fromJson(res.data);
    }
  }

  @override
  Widget build(BuildContext context) {
    return new Scaffold(
        appBar: new AppBar(
          title: new Text(widget.title),
        ),
        body: Column(
          children: [
            Container(
              height: 140.0,
              child: new Swiper(
                itemBuilder: (BuildContext context, int index) {
                  // return LoadImage('home/h_banner');
                  return LoadImage('https://osscdn.fanbao.cn/pro/2020-12-29/MEMBER_MARKETING_IMG/1609219262696231b372b6080bb8bb5c6cb065a0ab2a8.png');
                },
                itemCount: 3,
                pagination: new SwiperPagination(),
                control: new SwiperControl(),
              ),
            ),
            InkWell(
              onTap: _testRequest,
              child: Container(
                width: 80,
                height: 80,
                child: Text('点击请求'),
              ),
            )
          ],
        ));
  }
}
